<?php
/**
 * 会员升级订单支付成功回调
 */
namespace app\common\model\order;
use app\common\model as M;

class UserRaise extends OrderAbtract
{
   /**
    * 订单回调
    * @param    object            $order [description]
    * @return   function                     [description]
    */
   public function paid_callback( $order )
   {
        ## 记录设置为已支付
        $record = M\UserLevelRecords::where('id',$order->order_outer_id)->find();
        if ( empty($record) ) throw new \Exception('开通记录无效');

        $userLevelId = $record->level_id;
        $record->is_paid = 1;
        $res = $record->save();
        if ( $res === false ) throw new \Exception('更新开通记录支付状态失败');

        ## 设置用户等级ID
        $user = M\User::where('uid' , $order->uid)->find();
        if ( empty($user) ) throw new \Exception('用户无效');

        $user->level_id = $userLevelId;
        $res = $user->save();
        if ( $res === false ) throw new \Exception('更新用户等级失败');
        return true;
   }

   /** 获取订单编号前缀 */
   protected static function get_order_no_prefix()
   {
      return 'URA';
   }

   /** 获取订单类型 */
   protected static function get_order_type()
   {
      return \app\common\model\Order::ORDER_TYPE_RAISE;
   }
} //Class End